﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using FrienDev.BusinessRules;
using FrienDev.Data;

public partial class Controls_Message_SendMessageBox : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.rpt_Send.DataSource = MessageRules.Instance.GetCurrentUserSendMessage();
        this.rpt_Send.DataBind();
    }
    
    protected void rpt_Send_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            string messageId = e.CommandArgument.ToString();
            MessageRules.Instance.DeleteSessionMessageByMessageId(messageId.ToString());
            this.rpt_Send.DataSource = MessageRules.Instance.GetCurrentUserMessages();
            this.rpt_Send.DataBind();
        }
     }
    protected void rpt_Send_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Message message = e.Item.DataItem as Message;
        Literal temp_ltShortMessage = e.Item.FindControl("lt_SendedShortMessage") as Literal;
        temp_ltShortMessage.Text = message.MessageContent;
        HyperLink temp_hySender = e.Item.FindControl("hy_SUserName") as HyperLink;
        temp_hySender.Text = UserRules.Instance.GetUserByUserId(message.SenderId).FullName;
        temp_hySender.NavigateUrl = ApiHelper.Instance.GetUserHomepageLink(message.SenderId);
        Literal temp_ltSendDateTime = e.Item.FindControl("lt_SendTimeBySender") as Literal;
        temp_ltSendDateTime.Text = message.SendDateTime.ToShortDateString();
        //Image temp_imgOnlineLogo = e.Item.FindControl("SOnlineLogo") as Image;
        HyperLink temp_hyViewMessage = e.Item.FindControl("hy_ViewSendMessage") as HyperLink;
        temp_hyViewMessage.NavigateUrl = MessageRules.Instance.ViewSendMessageUrl(message.MessageId.ToString());
        LinkButton temp_lbtCloseSend = e.Item.FindControl("lbt_SendBoxClose") as LinkButton;
        temp_lbtCloseSend.CommandArgument = message.MessageId.ToString();
        Image temp_RMPhoto = e.Item.FindControl("img_RMPhoto") as Image;
        temp_RMPhoto.ImageUrl = ApiHelper.Instance.GetUserLogoUrl(message.User.UserId);
       

    }
        
}
